$(document).ready(function(){

    jQuery.validator.addMethod("isPhoneNumber", function(value, element) {
        var length = value.length;
        var phone = /(^(\d{3,4}-)?\d{6,8}$)|(^(\d{3,4}-)?\d{6,8}(-\d{1,5})?$)|^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
        return this.optional(element) || (phone.test(value));
    }, "请填写正确的固话或者手机号码！");

	$("form:eq(0)").validate({
        rules: {
        	groupName:{ 
        		required: true,
                minlength: 1,
                remote:{
                    url: '/UserManage/checkgroupname',
                    type: "post",
                    data : {
                        groupId: function(){
                            return $("#groupId").val();
                        },
                        groupName: function(){
                            return $("#groupName").val();
                        }
                    }
                }
        	},
            phoneNumber: {
                required: true,
                isPhoneNumber: true
            }
        },
        messages: {
        	groupName:{
	    		required: '请填写组织名称',
	    		minlength: '资源名称不少于1个字符',
                remote:'组名称已存在，请重新输入！'
	    	},
            phoneNumber: {
                required: '请填写电话号码',
                isPhoneNumber: '请填写正确的固话或者手机号码！'
            }
        }
    });
});
